
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta content="yes" name="apple-mobile-web-app-capable">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<meta content="telephone=no" name="format-detection">
	<meta content="no-cache" http-equiv="Cache-Control">
	<title>源之东方</title>
	<link href="__STATIC__/css/shopin.css" rel="stylesheet"/>
	<link href="__STATIC__/css/loading.css" rel="stylesheet"/>
</head>
<body>
<div class="header fixed-bar">
	<div class="left"><a href="javascript;" class="a-back"><span>返回</span></a></div>
	<div class="center">
		<button>
			{if ($state)}
			已签到
			{else}
			签到
			{/if}
		</button>
	</div>
</div><!--//头部结束-->

<div class="content">
	<div class="my-point pd flex">
		<div class="info cell">
			<div style="display: none;">{$user.username}</div>
			我的积分：{$user.intergral}
			<p class="hint">积分可用于抽奖、兑换礼品</p>
		</div>
		<a class="btn btn-submit addPoint" href="javascript:">士兵</a>
	</div>
	<h5 class="ht">积分明细(积分可通过购物、签到等获得)</h5>
	{if ($list)}
	<ul class="point">
		{volist name="list" id="v"}
		<li class="flex">
			<div class="cell">
				{if ($v.status==0)}
				新会员注册送积分
				{elseif($v.status ==1)}
				签到
				{else}
				购物
				{/if}
				<p class="hint">{$v.signed_time|date="Y-m-d H:i:s", ###}</p>
			</div>
			<span class="num f-red">+{$v.number}</span>
		</li>
		{/volist}
	</ul>
</div>
{else}
<div class="empty">
	<div class="empty-pic cry-pic"></div>
	<div class="empty-text">您还没有积分，快去购物赚取积分吧！</div>
	<div class="empty-btn"><a href="index.html" class="btn">去逛逛</a></div>
</div>
{/if}
<div class="point-fixed">
	<div class="add-point">
	</div>
</div>
<div class="mask"></div>
<div class="loading">
	<span>加载中...</span>
	<div class="pswp__preloader__icn">
		<div class="pswp__preloader__cut">
			<div class="pswp__preloader__donut"></div>
		</div>
	</div>
</div>
<script src="__STATIC__/js/zepto.min.js"></script>
<script src="__STATIC__/js/shopin.js"></script>
<script>
	//显示补录积分弹层
	$('.addPoint').on('tap', function() {
		$('html').addClass('active-page');
		$('.point-fixed').addClass('point-move');
		$('.mask').css('display','block');
		$.ajax({
			type:"get",
			url:"/sign/grade",
			async:true,
			success:function(data){
				var datas = JSON.parse(data);
				$('.add-point').html('<li><span>士兵</span><span>'+datas.士兵+'</span></li>'+
									'<li><span>排长</span><span>'+datas.排长+'</span></li>'+
									'<li><span>连长</span><span>'+datas.连长+'</span></li>'+
									'<li><span>营长</span><span>'+datas.营长+'</span></li>'+
									'<li><span>团长</span><span>'+datas.团战+'</span></li>');
			},
			error:function(error){
				console.log(error);
			}
		});
	});
	//点击遮罩关闭补录积分弹层
	$('.mask').on('tap', function(){
		$('.point-fixed').addClass('point-back');
		setTimeout("closePoint()", 200 )
	});

	////点击确定
	//var _len_point = 0;
	//_len_point = $('#receipt').on('input', function() {
	//	_len_point = this.value.length;
	//	submitAddPoint();
	//}).val().length;
	function submitAddPoint() {
		if (_len_point == 9) {
			$('.submitAddPoint').removeClass('disabled');
		} else {
			$('.submitAddPoint').addClass('disabled');
		}
	}
	$('.submitAddPoint').on('tap', function(event) {
		if(!$(this).hasClass('disabled')){
			$(this).addClass('disabled');
			//这里写补录积分的AJAX
			alert('补录成功');
			//成功后调取 closePoint()
			closePoint();
		}
	});
	//关闭补录积分
	function closePoint(){
		$('html').removeClass('active-page');
		$('.mask').css('display','none');
		$('.point-fixed').removeClass('point-move');
		$('.point-fixed').removeClass('point-back');
	};
	//加载更多
	function getScrollTop() {
		var scrollTop = 0;
		if (document.documentElement && document.documentElement.scrollTop) {
			scrollTop = document.documentElement.scrollTop;
		} else if (document.body) {
			scrollTop = document.body.scrollTop;
		}
		return scrollTop;
	}

	function getClientHeight() {
		var clientHeight = 0;
		if(document.body.clientHeight && document.documentElement.clientHeight) {
			clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
		} else {
			clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
		}
		return clientHeight;
	}

	function getScrollHeight() {
		return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
	}

	var obj = true;

	var page = 0;
	//滚动事件触发
	window.onscroll = function() {
		if(getScrollTop() + getClientHeight() == getScrollHeight()) {

			//此处发起AJAX请求
			$.ajax({
				type: "get",
				dataType: 'json',
				data: {
					page: page,
					number: 6
				},
				url: "/un_pay_json",
				async: true,
				success: function(data) {
					var data = data.data;
					console.log(data);
					if(data=="" || data==null) {
						var obj = false;
						$('.loading').css('display','block');
						$('.loading').html('');
						$('.loading').html('<div class="mls">大哥！这是我底线</div>');
					}else{
						if(data.length<6){
							var obj = false;
							$('.loading').css('display','block');
							$('.loading').html('');
							$('.loading').html('<div class="mls">大哥！这是我底线</div>');
						}
						page++;

						for(var i =0;i<data.length;i++){
							//遍历
							
						}
					}
				},
				error: function(error) {
					//异常处理；
					console.log(error);
				}
			});
		}
	}
	//签到
	$('.center button').click(function(){
		$.ajax({
			type:"get",
			url:"/myself/sign",
			data:{
				username:$('.info div').text()
			},     
			async:true,
			success:function(data){
				var j =  JSON.parse(data);
				console.log(j)
				if(j.code=='200'){
					alert('签到成功！');
					window.location.href='';
				}
			},
			error:function(error){
				console.log(error);
			}
		});
	})
</script>
</body>
</html>